<template>
  <div>
    <CommomProductList :paramProductType="4"/>
  </div>
</template>

<script>
import CommomProductList from '../components/commomProductList'

export default {
  name: 'microShopProductList',
  props: {},
  components: { CommomProductList },
  data() {
    return {
    }
  },
  computed: {},
  watch: {},
  methods: {
    
  },
  created() {
  },
  mounted() {
  },
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
}
</script>


<!-- <template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.identifier" placeholder="商品编号" class="filter-item" clearable/>
      <el-input v-model="listQuery.name$lk" placeholder="商品名称" class="filter-item" clearable/>
      <Cascader v-model="listQueryCategoryId" ref="listQueryCategoryId" placeholder="商品分类" :options="categoryData"
        :props="props" class="filter-item" style="width: 210px;" />
      <el-select v-model="listQuery.status" placeholder="状态" clearable class="filter-item">
        <el-option v-for="item in statusJson" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-select v-model="listQuery.isSample" placeholder="样品" clearable class="filter-item">
        <el-option v-for="item in sampleJson" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-select v-model="listQuery.type" placeholder="商品类型" clearable class="filter-item">
        <el-option v-for="item in typeJson" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-cascader class="filter-item" style="width: 210px;" v-model="storeId" :options="storeList"
        :props="{ checkStrictly: true,value:'id',label:'name' }" clearable placeholder="仓位"></el-cascader>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"
        >
        查询
      </el-button>
      <el-button class="filter-item" type="primary" icon="el-icon-edit" @click="toSave(0)">
        添加
      </el-button>
      <el-button class="filter-item" type="warning" icon="el-icon-sort" @click="handleFrozen">
        上下架
      </el-button>
      <el-button class="filter-item" type="danger" icon="el-icon-delete" @click="handlePlDelete"
        >
        批量删除
      </el-button>
      <el-button v-waves class="filter-item" type="success" icon="el-icon-view" @click="checkStore">
        查看仓位
      </el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row row-key="id" style="width: 100%;"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" />
      <el-table-column label="序号" type="index" align="center" width="60px" />
      <el-table-column label="序号" prop="sequence" align="center" width="80px" />
      <el-table-column label="商品编号" prop="identifier" align="center" />
      <el-table-column label="商品名称" prop="name" align="center" />
      <el-table-column label="商品分类" prop="categoryName" align="center" />
      <el-table-column label="编号" prop="identifier" align="center" />
      <el-table-column label="定价" prop="priceText" align="center" />
      <el-table-column label="库存" prop="store" align="center" />
      <el-table-column label="销量" prop="saleNum" align="center" />
      <el-table-column label="仓位" prop="storeName" align="center" />
      <el-table-column label="审核状态" align="center">
        <template slot-scope="{row}">
          <el-tag :type="row.status | statusFilter">
          {{ returnValueToLable(row.status,statusJson) }}
        </el-tag>
          <span>{{ returnValueToLable(row.status,statusJson) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核意见" prop="statusRemark" align="center" />
      <el-table-column label="类型" prop="type" align="center">
        <template slot-scope="{row}">
          <el-tag type="success">{{ row.isSeckillText }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button size="mini" @click="handleDetail(row)">
            查看
          </el-button>
          <el-button type="primary" size="mini" @click="toSave(row.id)">
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize"
      @pagination="getList" />
    
    <el-dialog title="详情" :visible.sync="dialogDetailVisible" width="800px">
      <el-card class="box-card" shadow="hover">
        <div slot="header" class="clearfix">
          <span>商品SKU</span>
        </div>
        <el-table :data="detail.skuList" style="width: 100%">
          <el-table-column v-for="(item,index) in skuHeader" :key="index" :label="item.label" :prop="item.value"
            align="center" />
        </el-table>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogDetailVisible = false">
          确定
        </el-button>
      </div>
    </el-dialog>

  </div>
</template> -->

<!-- <script>
import CommomProductList from '../components/commomProductList'

import { categoryPageVoByQo, productPageByQo, productFrozen, productRemoveByIds, copyToC, productGetById } from '@/api/product'
import { storePageByQo } from '@/api/store'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import Cascader from '@/components/Cascader'

export default {
  name: 'microShopProductList',
  directives: { waves },
  components: { CommomProductList, Cascader, Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: 'danger',
        1: 'success',
        2: '',
        3: 'info'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        pageNo: 1,
        pageSize: 20,
        name$lk: '',
        identifier: '',
        categoryId: '',
        status: '',
        storeId: '',
        isSample: '',
        type: '3',
        isSeckill: 0
      },
      multipleSelection: [],
      categoryData: [],
      props: { value: 'id', label: 'name' },
      listQueryCategoryId: '',
      statusJson: [
        { value: 0, label: '已下架' },
        { value: 1, label: '已上架' },
        { value: 2, label: '审核中' },
        { value: 3, label: '已拒绝' },
      ],
      sampleJson: [
        { value: 0, label: '否' },
        { value: 1, label: '是' },
      ],
      typeJson: [
        { value: 1, label: '众茶通App商品' },
        { value: 2, label: '众茶通小程序商品' },
      ],
      storeList: [],
      storeId: '',
      dialogDetailVisible: false,
      detail:{},
      skuHeader: [
        { label: '规格名称', value: 'name' },
        { label: '参考价（元）', value: 'price' },
        { label: '计量单位(例:饼/件/盒/斤等)', value: 'unit' },
        { label: '净含量', value: 'weight' },
        { label: '库存', value: 'store' },
        { label: '起订量', value: 'startNum' },
      ]
    }
  },
  watch: {
    listQueryCategoryId(val) {
      this.listQuery.categoryId = this.$refs['listQueryCategoryId'].getIds(val)
    },
    storeId(val) {
      this.listQuery.storeId = val && val.length ? val[val.length - 1] : ''
    },
    $route: {
      handler: function(route) {
        const t = route.query.t;
        if (t) {
          this.getList()
        }
      },
      immediate: true
    }
  },
  created() {
    this.getList()
    this.getCategory()
    this.getStoreList()
  },
  methods: {
    getCategory() {
      categoryPageVoByQo().then((res) => {
        this.$set(this, 'categoryData', res || [])
      })
    },
    getStoreList() {
      storePageByQo().then((res) => {
        this.$set(this, 'storeList', res || [])
      })
    },
    getList() {
      this.listLoading = true
      productPageByQo(this.listQuery).then(response => {
        this.list = response.list || []
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    },
    toSave(id) {
      this.$router.push({
    		path: "/microShop/microShopProductSave",
    		query: {
    			id: id,
          productType: 4
    		}
    	});
    },
    uploadSecKillProduct(id) {
      this.$router.push({
    		path: "/shop/killProductSave",
    		query: {
    			id: id,
          productType: 1,
          isCopySecKillGood: true
    		}
    	});
    },
    handleFrozen() {
      if (!this.multipleSelection || this.multipleSelection.length < 1) {
        this.$message.error('请至少选择一条数据')
        return
      }
      const params = {
        ids: this.multipleSelection.join(',')
      }
      this.$confirm('是否继续操作？').then(() => {
        productFrozen(params).then(() => {
          // this.$notify({
          //   title: '成功',
          //   message: '设置成功！',
          //   type: 'success',
          //   duration: 2000
          // })

          this.$message({
            message: '设置成功！',
            type: 'success'
          });
          this.getList()
        })
      })
    },
    // 批量操作
    handleSelectionChange(val) {
      this.multipleSelection = val.map((ele) => {
        return ele.id
      })
    },
    handlePlDelete() {
      if (!this.multipleSelection || this.multipleSelection.length < 1) {
        this.$message.error('请至少选择一条数据')
        return
      }
      const params = {
        ids: this.multipleSelection.join(',')
      }
      this.$confirm('是否继续删除？').then(() => {
        productRemoveByIds(params).then(() => {
          this.$message({
            message: '批量删除成功！',
            type: 'success'
          });
          this.getList()
        })
      })
    },
    checkStore() {
      this.$router.push('/store')
    },
    handleDetail(row) {
      this.getDetail(row.id).then(res => {
        this.detail = Object.assign({}, res)
        this.dialogDetailVisible = true;
      })
    },
    getDetail(id) {
      return new Promise((resolve, reject) => {
        productGetById({ id: id })
          .then(res => {
            resolve(res);
          })
          .catch(err => {
            reject(err);
          });
      });
    },
  }
}
</script> -->
